<?php

class ResourceAction extends CommonAction {

    public function index() {
        $model = D('Resource');
        $list = $model->get_tree_list(0, 0, false, 0);
        $this->assign('list', $list);
        Cookie::set('_currentUrl_', __SELF__);
        $this->display();
    }

    public function add() {
        $model = D('Resource');
        $this->assign('cat_select', $model->get_tree_list());
        F('list_resource', null);
        CommonAction::add();
    }

    public function remove() {
        $id = intval($_REQUEST['id']);
        $model = D('Resource');
        $count = $model->where('pid=' . $id)->count();
        if ($count > 0) {
            $this->error('子级还有数据,不能删除!');
            exit;
        }
        F('list_resource', null);
        CommonAction::delete();
    }

    public function _toggle() {
        $model = D('Resource');
        F('list_resource', null);
        if (false != $model->where('id=' . $_REQUEST['id'])->setField($_REQUEST['field'], $_REQUEST['val'])) {
            $this->ajaxReturn($_REQUEST['val']);
        } else {
            $this->error('修改状态出错!');
        }
    }

    public function _ltedit() {
        $model = D('Resource');
        F('list_resource', null);
        if (false === $model->where('id=' . $_REQUEST['id'])->setField($_REQUEST['field'], $_REQUEST['val'])) {
            $this->error('修改状态出错!' . $model->getLastSql());
        } else {
            $this->ajaxReturn($_REQUEST['val']);
        }
    }

}

?>
